package cn.sdormitory.controller.sys;


import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.sys.entity.SysAppVersion;
import cn.sdormitory.sys.service.SysAppVersionService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "Sys-App => app版本管理")
@RestController
@RequestMapping("/sys/app")
public class SysAppVersionController {

    @Autowired
    SysAppVersionService sysAppVersionService;

    @ApiOperation("pageList => 获取app版本列表")
    @PostMapping("/findAppVersionByPageList")
    public CommonResult<CommonPage<SysAppVersion>> findAppVersionByPageList(@RequestBody SysAppVersion appVersion){
        IPage<SysAppVersion> pageList = sysAppVersionService.findAppVersionByPageList(appVersion);
        return CommonResult.success(CommonPage.restPage(pageList));
    }

    @ApiOperation("create => 新增app版本列表")
    @PostMapping("/createAppVersion")
    public CommonResult<Integer> createAppVersion(@RequestBody SysAppVersion appVersion){
        Integer count = sysAppVersionService.createAppVersion(appVersion);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }


    @ApiOperation("delete => 删除app版本列表")
    @DeleteMapping("/deleteAppVersion/{id}")
    public CommonResult<Integer> deleteAppVersion(@PathVariable("id")Long id){
        Integer count = sysAppVersionService.deleteAppVersion(id);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

}
